
package com.x52im.rbchat.logic.alarm.model;

import com.eva.epc.common.util.CommonUtils;

import java.util.Observer;

   /**
	 * BBS(世界频道)的Alarm数据结构实现类.
	 */
	public class BBSAlarmDataObservable
	{
		private AlarmDto data = null;
		private Observer observer = null;
		
		public void setData(String title, String msg, long date, String friendUID, String flagNum)
		{
			if(data == null)
				data = new AlarmDto();

			data.setDataId(friendUID);
			data.setTitle(title);
			data.setAlarmContent(msg);
			data.setDate(date);
//			data.setExtraObj(friendUID); // 额外对象字段存放的是发消息人的uid
			data.setFlagNum(flagNum);
			
			notifyObserver();
		}

		public AlarmDto getData(){
			return this.data;
		}
		
		public int getFlagNum()
		{
			return CommonUtils.getIntValue(data == null ? "0": data.getFlagNum());
		}

		/**
		 * 重置未读数为0.
		 *
		 * @param notify 是否需要通知观察者
		 */
		public void resetFlagNum(boolean notify)
		{
			if(data != null) {
				data.setFlagNum("0");
				if(notify) {
					notifyObserver();
				}
			}
		}
		
		private void notifyObserver()
		{
			if(observer != null)
				observer.update(null, data);
		}

		public void setObserver(Observer observer)
		{
			this.observer = observer;
		}
	}